<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.server.api.dao.${className}Dao">

    <select id="findList" parameterType="com.server.api.dto.${className}DTO" resultType="com.server.api.dto.${className}DTO">
        select
        <#if searchColsList??>
        <#--循环生成变量-->
            <#list searchColsList as col>
        ${col["fromTableName"]}.${col["colName"]}<#if col_has_next>,</#if>
            </#list>
        </#if>
        from ${tableName} ${unClassName}
        <#if correlation??>
        ${correlation}
        </#if>
        <where>
            <#if searchColsList??>
            <#--循环生成变量-->
                <#list searchColsList as col>
                    <#if col["compareWay"] == "like">
            <if test="${col["propertyName"]} != null and ${col["propertyName"]} != ''">and ${col["fromTableName"]}.${col["colName"]} like concat('%',<#noparse>#{</#noparse>${col["propertyName"]}<#noparse>}</#noparse>,'%')</if>
                    <#else>
            <if test="${col["propertyName"]} != null and ${col["propertyName"]} != ''">and ${col["fromTableName"]}.${col["colName"]} = <#noparse>#{</#noparse>${col["propertyName"]}<#noparse>}</#noparse></if>
                    </#if>
                </#list>
            </#if>
        </where>
        <if test="current != null and pageSize != null">
            limit <#noparse>#{</#noparse>current<#noparse>}</#noparse>,<#noparse>#{</#noparse>pageSize<#noparse>}</#noparse>
        </if>
    </select>

    <select id="findPageCount" parameterType="com.server.api.dto.${className}DTO" resultType="java.lang.Integer">
        select count(*) from ${tableName} ${unClassName}
        <#if correlation??>
        ${correlation}
        </#if>
        <where>
            <#if searchColsList??>
            <#--循环生成变量-->
                <#list searchColsList as col>
                    <#if col["compareWay"] == "like">
        <if test="${col["propertyName"]} != null and ${col["propertyName"]} != ''">and ${col["fromTableName"]}.${col["colName"]} like concat('%',<#noparse>#{</#noparse>${col["propertyName"]}<#noparse>}</#noparse>,'%')</if>
                    <#else>
        <if test="${col["propertyName"]} != null and ${col["propertyName"]} != ''">and ${col["fromTableName"]}.${col["colName"]} = <#noparse>#{</#noparse>${col["propertyName"]}<#noparse>}</#noparse></if>
                    </#if>
                </#list>
            </#if>
        </where>
    </select>

    <select id="find" parameterType="com.server.api.dto.${className}DTO" resultType="com.server.api.dto.${className}DTO">
        select
        <#if searchColsList??>
        <#--循环生成变量-->
            <#list searchColsList as col>
        ${col["fromTableName"]}.${col["colName"]}<#if col_has_next>,</#if>
            </#list>
        </#if>
        from ${tableName} ${unClassName}
        <#if correlation??>
        ${correlation}
        </#if>
        <where>
            <#if searchColsList??>
            <#--循环生成变量-->
                <#list searchColsList as col>
                    <#if col["compareWay"] == "like">
            <if test="${col["propertyName"]} != null and ${col["propertyName"]} != ''">and ${col["fromTableName"]}.${col["colName"]} like concat('%',<#noparse>#{</#noparse>${col["propertyName"]}<#noparse>}</#noparse>,'%')</if>
                    <#else>
            <if test="${col["propertyName"]} != null and ${col["propertyName"]} != ''">and ${col["fromTableName"]}.${col["colName"]} = <#noparse>#{</#noparse>${col["propertyName"]}<#noparse>}</#noparse></if>
                    </#if>
                </#list>
            </#if>
        </where>
        limit 1
    </select>

</mapper>
